package com.llkj.common.model;

import com.google.gson.annotations.SerializedName;

/**
 * author: zhu.px
 * e-mail: 1271901673@qq.com
 * time  : 2018/4/23
 * desc  : 数据基类
 */
public class BaseResponse<T> {

    /**
     * HTTP请求成功状态码
     */
    public static final int HTTP_SUCCESS = 00;
    /**
     * AccessToken错误或已过期
     */
    public static final int ACCESS_TOKEN_EXPIRED = 10001;
    /**
     * RefreshToken错误或已过期
     */
    public static final int REFRESH_TOKEN_EXPIRED = 10002;
    /**
     * 帐号在其它手机已登录
     */
    public static final int OTHER_PHONE_LOGIN = 10003;
    /**
     * 时间戳过期
     */
    public static final int TIMESTAMP_ERROR = 10004;
    /**
     * 缺少授权信息,没有AccessToken
     */
    public static final int NO_ACCESS_TOKEN = 10005;
    /**
     * 签名错误
     */
    public static final int SIGN_ERROR = 10006;

    @SerializedName("returnCode")
    private int code;
    @SerializedName("message")
    private String msg;
    @SerializedName("res")
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg == null ? "" : msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "BaseResponse{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public boolean isOk() {
        return code == HTTP_SUCCESS;
    }
}
